package com.bawei.bydayzg_two.viewModel

import androidx.lifecycle.viewModelScope
import com.bawei.base.bean.GoodsResult
import com.bawei.base.bean.Res
import com.bawei.base.http.SingleLiveData
import com.bawei.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch
import retrofit2.http.Query

class SearchViewModel:BaseViewModel() {

    //请求商品
    val goodsSuccess = SingleLiveData<Res<GoodsResult>>()
    val goodsFail = SingleLiveData<String>()
    //
    fun goods(cid:Int,
              keyword:String,
              limit:Int,
             news:Boolean,
             page:Int,
             priceOrder:String,
              salesOrder:String){
        viewModelScope.launch {
            try {
                goodsSuccess.postValue(apiService.goods(cid, keyword, limit, news, page, priceOrder, salesOrder))
            } catch (e: Exception) {
                goodsFail.postValue(e.message.toString())
            }
        }
    }
}